package com.zmn.plat.services.impl.pilot;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.pilot.ChannelPriceCategory;
import com.zmn.plat.model.entity.pilot.ChannelPriceCategoryQuery;
import com.zmn.plat.persistence.interfaces.pilot.ChannelPriceCategoryDao;
import com.zmn.plat.services.interfaces.pilot.ChannelPriceCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 试点产品分类（渠道试点、城市试点）接口实现类
 *
 * @author guoqiao
 * @since 2021-06-25 10:16:42
 */
@Slf4j
@Service
public class ChannelPriceCategoryServiceImpl implements ChannelPriceCategoryService {

    private static final String TAG = "试点产品分类（渠道试点、城市试点）基础服务接口";

    @Resource
    private ChannelPriceCategoryDao channelPriceCategoryDao;

    @Override
    public ChannelPriceCategory findById(Integer id) {

        if (Objects.isNull(id)) {
            log.error("[{}],根据id查询数据id为null", TAG);
            return null;
        }
        return channelPriceCategoryDao.findById(id);
    }

    @Override
    public List<ChannelPriceCategory> listPageByQuery(ChannelPriceCategoryQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        query.setTotalCount(channelPriceCategoryDao.countByQuery(query));
        return channelPriceCategoryDao.listPageByQuery(query);
    }

    @Override
    public List<ChannelPriceCategory> listByQuery(ChannelPriceCategoryQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return channelPriceCategoryDao.listByQuery(query);
    }

    @Override
    public Integer countByQuery(ChannelPriceCategoryQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return channelPriceCategoryDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(ChannelPriceCategory channelPriceCategory) {

        if (Objects.isNull(channelPriceCategory.getId())) {
            log.error("[{}],根据id修改数据,channelPriceCategory为null", TAG);
            return null;
        }
        return channelPriceCategoryDao.updateByKey(channelPriceCategory);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, String operator) {

        if (!Objects.equals(status, GlobalConsts.NO) && !Objects.equals(status, GlobalConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        channelPriceCategoryDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public Integer insert(ChannelPriceCategory channelPriceCategory) {

        if (Objects.isNull(channelPriceCategory)) {
            log.error("[{}],新增数据,channelPriceCategory为null", TAG);
            return null;
        }
        return channelPriceCategoryDao.insert(channelPriceCategory);
    }


    @Override
    public int insertBatchs(List<ChannelPriceCategory> list) {
        return channelPriceCategoryDao.insertBatchs(list);
    }

    @Override
    public Integer deleteByKey(Integer id) {

        if (Objects.isNull(id)) {
            log.error("[{}],根据id删除数据,id为null", TAG);
            return null;
        }
        return channelPriceCategoryDao.deleteByKey(id);
    }

    @Override
    public int deleteByConfigIdAndServCategId(Integer configId, Integer servCategId, Integer type, Integer showType) {
        return channelPriceCategoryDao.deleteByConfigIdAndServCategId(configId, servCategId, type, showType);

    }
    @Override
    public int deleteByConfigId(Integer configId, Integer type, Integer showType) {
        return channelPriceCategoryDao.deleteByConfigId(configId,type,showType);

    }

}